<?php

/**
 * InfractionModel
 */
include_once 'Application/Views/infraction/InfractionView.php';
class Application_Models_InfractionModel{
    private $_idInfraction;
    private $_idLicensePlate;
    private $_idType;
    private $_nameOffender;
    private $_infractionDate;
    private $_insteadInfraction;
    private $_cost;
    private $_description;
    
    function __construct() {
        
    }
    public function get_idInfraction() {
        return $this->_idInfraction;
    }

    public function set_idInfraction($_idInfraction) {
        $this->_idInfraction = $_idInfraction;
    }

    public function get_idLicensePlate() {
        return $this->_idLicensePlate;
    }

    public function set_idLicensePlate($_idLicensePlate) {
        $this->_idLicensePlate = $_idLicensePlate;
    }

    public function get_idType() {
        return $this->_idType;
    }

    public function set_idType($_idType) {
        $this->_idType = $_idType;
    }

    public function get_nameOffender() {
        return $this->_nameOffender;
    }

    public function set_nameOffender($_nameOffender) {
        $this->_nameOffender = $_nameOffender;
    }

    public function get_infractionDate() {
        return $this->_infractionDate;
    }

    public function set_infractionDate($_infractionDate) {
        $this->_infractionDate = $_infractionDate;
    }

    public function get_insteadInfraction() {
        return $this->_insteadInfraction;
    }

    public function set_insteadInfraction($_insteadInfraction) {
        $this->_insteadInfraction = $_insteadInfraction;
    }

    public function get_cost() {
        return $this->_cost;
    }

    public function set_cost($_cost) {
        $this->_cost = $_cost;
    }

    public function get_description() {
        return $this->_description;
    }

    public function set_description($_description) {
        $this->_description = $_description;
    }
    
    /**
     * registrar
     * 
     */
    public function insertInfraction(){
        global $config;                  
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();
        $columns="'"."$this->_idInfraction"."','"."$this->_idLicensePlate"."','"."$this->_idType".
                "','"."$this->_nameOffender"."','"."$this->_infractionDate"."','"."$this->_insteadInfraction".
                "','"."$this->_cost"."','"."$this->_description"."'";
        //die($columns);
        $query="CALL sp_registrar_infraccion(".$columns.")";
        //die($query);
        $consult=$objDb->selectManager()->select($query);
        header("Location: principal.php?action=show&controller=Infraction");
// die($consult);
        //$table=$config['tableInfraction'];
        //$consult=$objDb->selectManager()->insertAdd(strtoupper($columns), $table);
        /*$viewInfraction=new Application_Views_InfractionView();
        if($consult[][]){            
            $viewInfraction->formListInfraction("si se pudo");
        }else{
            $viewInfraction->formListInfraction("no se pudo");
        }*/
        
    }
    
    public static function showInfraction1(){
        global $config;
        
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $table=$config['tableInfraction'];        
        $columns="*";
        $consult=$objDb->selectManager()->selectAdd($columns, $table);
        $viewInfraction=new Application_Views_InfractionView();          
        $viewInfraction->showInfraction($consult);
    }
    /**
     * actualizar
     * 
    */ 
    public function updateInfraction(){
        global $config;
        
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $table=$config['tableInfraction'];
        /*$columns="'"."$this->_lastName"."','"."$this->_name".
                "','"."$this->_gender"."','"."$this->_dateBirth"."','"."$this->_address"."'";*/
        $condition="'$this->_idInfraction'";
        
        $query="update $table set id_placa='".$this->_idLicensePlate."',id_tipo='".$this->_idType."',
            nombre_infractor='".$this->_nameOffender."',fecha_infraccion='".$this->_infractionDate.
                "',lugar_infraccion='".$this->_insteadInfraction."',precio='".$this->_cost.
                "',descripcion='".$this->_description."' 
                where id_infraccion= $condition";
        //die($query);
        //$consult=$objDb->selectManager()->updateAdd($columns, $table, $condition);     
        $consult=$objDb->selectManager()->update(strtoupper($query));
        //die($consult);
        if($consult){
            //echo 'modificado con exito';
            header("Location: principal.php?action=show&controller=Infraction");
        }else{
            echo 'algo anda mal';
        }
    }


}